package com.po;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Set;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * BaseUser entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.po.BaseUser
 * @author MyEclipse Persistence Tools
 */

public class BaseUserDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(BaseUserDAO.class);
	// property constants
	public static final String DEPT_ID = "deptId";
	public static final String LOGIN_NAME = "loginName";
	public static final String PASSWORD = "password";
	public static final String NAME = "name";
	public static final String PHONE = "phone";
	public static final String EMAIL = "email";
	public static final String SEX = "sex";
	public static final String POSITION = "position";
	public static final String POSITION_DES = "positionDes";
	public static final String CREATE_USER_ID = "createUserId";
	public static final String MODIFY_USER_ID = "modifyUserId";
	public static final String TELEPHONE = "telephone";
	public static final String LEVELES = "leveles";

	public void save(BaseUser transientInstance) {
		log.debug("saving BaseUser instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(BaseUser persistentInstance) {
		log.debug("deleting BaseUser instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public BaseUser findById(java.lang.String id) {
		log.debug("getting BaseUser instance with id: " + id);
		try {
			BaseUser instance = (BaseUser) getSession().get("com.po.BaseUser",
					id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(BaseUser instance) {
		log.debug("finding BaseUser instance by example");
		try {
			List results = getSession().createCriteria("com.po.BaseUser").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding BaseUser instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from BaseUser as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByDeptId(Object deptId) {
		return findByProperty(DEPT_ID, deptId);
	}

	public List findByLoginName(Object loginName) {
		return findByProperty(LOGIN_NAME, loginName);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByPhone(Object phone) {
		return findByProperty(PHONE, phone);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findBySex(Object sex) {
		return findByProperty(SEX, sex);
	}

	public List findByPosition(Object position) {
		return findByProperty(POSITION, position);
	}

	public List findByPositionDes(Object positionDes) {
		return findByProperty(POSITION_DES, positionDes);
	}

	public List findByCreateUserId(Object createUserId) {
		return findByProperty(CREATE_USER_ID, createUserId);
	}

	public List findByModifyUserId(Object modifyUserId) {
		return findByProperty(MODIFY_USER_ID, modifyUserId);
	}

	public List findByTelephone(Object telephone) {
		return findByProperty(TELEPHONE, telephone);
	}

	public List findByLeveles(Object leveles) {
		return findByProperty(LEVELES, leveles);
	}

	public List findAll() {
		log.debug("finding all BaseUser instances");
		try {
			String queryString = "from BaseUser";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public BaseUser merge(BaseUser detachedInstance) {
		log.debug("merging BaseUser instance");
		try {
			BaseUser result = (BaseUser) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(BaseUser instance) {
		log.debug("attaching dirty BaseUser instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(BaseUser instance) {
		log.debug("attaching clean BaseUser instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}